﻿Public Class MuhOdemeEmriYazim
	Inherits ProcessReport

	Dim eno As Input

	Public Overrides Sub GenericEvent(ByVal e As ProcessEventArgs)
		Select Case e.EventType
			Case EventType.Initialize
				Start("Ödeme Emri Yazımı", "Ödeme emri numarasını girin.")
				eno = AddOdemeEmri()
				Landscape = True
			Case EventType.ValidateForm
				Rs = Muhasebe.OdemeEmri.Oku(Remote, eno.Get)
				If Check("eno", Rs.EOF, "Ödeme emri bulunamadı.") Then Return
				e.Result = True
			Case EventType.ReportDetail
				Dim MaxLine As Integer = 19
				Report.NoPageNumbers = True
				Dim Rsg As Recordset = Muhasebe.OdemeEmri.Oku(Remote, eno.Get)
				Dim Rsc As Recordset = Muhasebe.OdemeEmri.CekListesi(Remote, eno.Get)
				Dim Rs(1) As Recordset
				Rs(0) = Muhasebe.OdemeEmri.Hesap(Remote, eno.Get, True)
				Rs(1) = Muhasebe.OdemeEmri.Hesap(Remote, eno.Get, False)
				Dim PageCount As Integer = Int((Math.Max(Rs(0).Count, Rs(1).Count) + 1) / MaxLine)
				For Page As Integer = 0 To PageCount
					Report.BeginBorders().SetColumns("", "4;6;2;2", "c;c;c;c", "")
					Report.Indent = New Padding(6)
					Report.AddBookmark()
					Report.Print("<rs=2><b><+>SOSYAL SİGORTALAR DAİRESİ", "<rs=2><b><++>ÖDEME EMRİ", "<b>Tarih", "<b>Ödeme Emri No")
					Report.Print(DMY(Rsg("tarih")), Rsg("eno"))
					Report.SetColumns("", "3;2;2;1;2", "c;c;c;c;c", "")
					Report.EndBorders()
					Report.Indent = New Padding(4)
					Report.Print("Alacaklı", "Ref.no. aralığı", "Çek no. aralığı", "Çek sayısı", "Toplam ödeme tutarı")
					Report.Print(Rsg("alacakli"), Rsg("cekbasno") & "-" & Rsg("cekbitno"), Rsc.Min("ceknoyeni") & "-" & Rsc.Max("ceknoyeni"), Rsg("ceksay"), Fm(Rsg("cektoplam"), "TL"))
					Report.BeginBorders()
					Report.Indent = New Padding(3, 2, 3, 2)
					Report.AddBookmark()
					Report.SetColumns("", "3;8;3;1;3;8;3;1", "c;l;r;c;c;l;r;c", "--")
					Report.Print("<cs=2><b>Borçlu Hesaplar", "<cs=2><b>Tutarı", "<cs=2><b>Alacaklı Hesaplar", "<cs=2><b>Tutarı")
					Report.Print("<b>Hesap no.", "<b>Hesap ismi", "<b>TL", "<b>Kr", "<b>Hesap no.", "<b>Hesap ismi", "<b>TL", "<b>Kr")
					Report.AddBookmark()
					For i As Integer = 1 To MaxLine
						Dim c(7) As String
						If Rs(0).EOF And Rs(1).EOF Then Exit For
						For x As Integer = 0 To 1
							If Not Rs(x).EOF Then
								c(x * 4 + 0) = Rs(x)("hesapno")
								c(x * 4 + 1) = Rs(x)("hesapadi")
								c(x * 4 + 2) = MoneyPart(Rs(x)(If(x = 0, "borc", "alacak")), 1)
								c(x * 4 + 3) = MoneyPart(Rs(x)(If(x = 0, "borc", "alacak")), 2)
								Rs(x).MoveNext()
							End If
						Next
						Report.Print(c(0), c(1), c(2), c(3), c(4), c(5), c(6), c(7))
					Next
					Report.SetColumns("", "1", "c")
					Report.PrintFlexible()
					Report.SetColumns("", "11;3;1;11;3;1", "r;r;c;r;r;c", "--")
					If Page = PageCount Then
						Dim Toplam(1) As Decimal
						Toplam(0) = Rs(0).Sum("borc")
						Toplam(1) = Rs(1).Sum("alacak")
						Report.Print("<b>TOPLAM", MoneyPart(Toplam(0), 1), MoneyPart(Toplam(0), 2), "<b>TOPLAM", MoneyPart(Toplam(1), 1), MoneyPart(Toplam(1), 2))
						Report.CenteredLine()
						Report.AddBookmark()
						Report.Indent = New Padding(6)
						Report.Print("Yalnız -- " & NumberToText(Toplam(0)) & " --")
					Else
						Report.AddBookmark()
					End If
					Report.AddBookmark()
					Report.SetColumns("", "6;3;3;2;4", "c;c;c;c;c")
					Report.Indent = New Padding(6)
					Report.Print("<b>Açıklama", "<b><cs=2>Ödeme Emrini", "<b><cs=2>Yukarıda belirtilen tutarların ödenmesi uygundur.")
					Report.Print("<rs=3><w>" & Rsg("acik"), "<b>Hazırlayan", "<b>Kontrol Eden", "<rs=2><cs=2>")
					Report.Print("<l>İmza:", "<l>İmza:")
					Report.Print("<l>İsim:", "<l>İsim:", "Tarih", "Sosyal Sigortalar Dairesi Müdürü")
					Report.AddBookmark()
					For s As Integer = 1 To 5
						Report.DrawRect(0, Report.Bookmark(s).Y, 1, Report.Bookmark(s + 1).Y, 2)
					Next
					Report.DrawRect(0, Report.Bookmark(2).Y, 0.5, Report.Bookmark(4).Y, 2)
					Report.DrawRect(0.5, Report.Bookmark(2).Y, 1, Report.Bookmark(4).Y, 2)
					Report.EndPage()
				Next
		End Select
	End Sub

End Class
